<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <input type="text">
    <button class="set">存</button>
    <button class="get">获取</button>
    <button class="remove">删除</button>
    <button class="del">清空</button>
    <script>
        // 本地存储分为sessionStorage,localStorage
        //window.sessionStorage,关闭窗口就没有
        var input = document.querySelector('input');
        var set = document.querySelector('.set');
        var get = document.querySelector('.get');
        var remove = document.querySelector('.remove');
        var del = document.querySelector('.del');
        set.addEventListener('click', function() {
            var val = input.value;
            sessionStorage.setItem('name', val);
            sessionStorage.setItem('pass', val);
        })
        get.addEventListener('click', function() {
            console.log(sessionStorage.getItem('name', val));
        })
        remove.addEventListener('click', function() {
            sessionStorage.removeItem('name');
        })
        del.addEventListener('click', function() {
            sessionStorage.clear();
        })
        // localStorage永久保存，关闭页面也存在，除非手动删除，多窗口使用
        // 和上边使用一样
    </script>
</body>
</html>